const XLSX = require('xlsx')
const path = require('path')
const fs = require('fs')
const xlsxPath = path.resolve(__dirname, './xlsx')
const JSONPath = path.resolve(__dirname, './json')

fs.readdir(xlsxPath, 'utf-8', (err, files) => {
  for(let fileName of files) {
    const xlsxDataPath = path.join(xlsxPath, fileName)
    const JSONDataPath = path.join(JSONPath, fileName.replace('xlsx', 'json').replace('-数据来源百度地图', ''))
    const workbook = XLSX.readFile(xlsxDataPath)
    var sheet_name_list = workbook.SheetNames;
    const _JSONData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]])
    fs.writeFileSync(JSONDataPath, JSON.stringify(_JSONData))
  }
})
